package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.advice.LonOperation;
import com.itheima.exception.TliasException;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper,Dept> implements DeptService {
   /* @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpMapper empMapper;

    *//**
     * 查询所有的部门
     * @return 部门集合
     *//*
    @Override
    @LonOperation
    public List<Dept> selectDept() {
        List<Dept> depts = deptMapper.selectList(null);
        return depts;
    }

    @Override
    public void deleteDept(Integer id) {
        //判断这个部门是否有员工
        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq("id" , id);

        Emp emp = new Emp();
        Long count = empMapper.selectCount(queryWrapper);

//        Integer count = empMapper.countByDeptId(id);
        if(count > 0){
            throw new TliasException("对不起 , 当前部门下有员工 , 不能直接删除");
        }
        deptMapper.deleteById(id);
    }

    @Override
    public void insertDept(Dept dept) {
        //给对象补全属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept selectDeptById(Integer id) {
        Dept dept = deptMapper.selectById(id);
        return dept;
    }

    @Override
    public void updateDept(Dept dept) {
        //补全数据
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateById(dept);
    }

*/
}

